import '../rule.dart';
import 'json_rule.dart';
import 'jsoup_rule.dart';
import 'regex_rule.dart';
import 'xpath_rule.dart';
import 'package:flutter_book/util/extensions/string_extensions.dart';

class SingleRule extends Rule {
  Mode mode;
  String ruleContent;

  SingleRule(this.mode, this.ruleContent);

  @override
  String toString() {
    return "{mode : $mode,ruleContent : $ruleContent}";
  }
}

enum Mode {
  XPath,
  Json,
  Default,
  // Js,
  Regex
}

class SingleParser extends IParser<SingleRule> {
  SingleParser(SingleRule rule) : super(rule);

  @override
  Future<String> getString(String content, {Map<String, dynamic>? valueMap}) async {
    switch (rule.mode) {
      // case Mode.Js:
      //   return JsParser(rule).getString(content);
      //   break;
      case Mode.Regex:
        return RegexParser(rule).getString(content, valueMap: valueMap);
      case Mode.Json:
        return JsonParser(rule).getString(content, valueMap: valueMap);
        break;
      case Mode.XPath:
        return XpathParser(rule).getString(content, valueMap: valueMap);
        break;
      case Mode.Default:
        //jsoup
        return JsoupParser(rule).getString(content, valueMap: valueMap);
        break;
    }

    // if(RegexChildParser.regex.hasMatch(rule.)){
    //   return RegexParser(rule).getString(content,valueMap: valueMap);
    // }
    return '';
  }

  @override
  Future<List<String>> getStringList(String content, {Map<String, dynamic>? valueMap}) async {
    switch (rule.mode) {
      // case Mode.Js:
      //   return JsParser(rule).getStringList(content);
      //   break;
//todo 等待更改
      case Mode.Regex:
        "Mode.Regex".print;
        return [];
      // return await RegexParser(rule).getStringList(content, valueMap: valueMap);
      case Mode.Json:
        "Mode.Json".print;
        return [];
        // return await JsonParser(rule).getStringList(content, valueMap: valueMap);
        break;
      case Mode.XPath:
        "Mode.XPath".print;
        return [];
        // return await XpathParser(rule).getStringList(content, valueMap: valueMap);
        break;
      case Mode.Default:
        "Mode.Default".print;
        //jsoup
        return await JsoupParser(rule).getStringList(content, valueMap: valueMap);
        break;
    }
    return <String>[];
  }
}
